<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>"/>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="favicon.ico">
    <link rel="Shortcut Icon" href="favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="assets/H-ui/lib/html5.js"></script>
    <script type="text/javascript" src="assets/H-ui/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="assets/H-ui/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="assets/H-ui/static/h-ui.admin/css/style.css"/>
    <%--<link rel="stylesheet" type="text/css" href="assets/css/build.css">--%>
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css">
    <!--复选框样式-->
    <link rel="stylesheet" type="text/css" href="assets/bootstrap-checkbox/css/awesome-bootstrap-checkbox.css"/>
    <!--复选框字体样式-->
    <link rel="stylesheet" href="assets/bootstrap-checkbox/Font-Awesome/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="assets/bootstrap-checkbox/css/build.css"/>

    <!--[if IE 6]>
    <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
    <!--<script>DD_belatedPNG.fix('*');</script>-->
    <%--<![endif]-->--%>
    <!--/meta 作为公共模版分离出去-->

    <title>权限分配</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

</head>

<body>
<article class="cl pd-20">
    <form action="power/up.action" method="post">
        <%--class="form form-horizontal" id="form-admin-role-add"--%>
        <div class="row cl">
            <div class="formControls col-xs-8 col-sm-9">
                <input type="hidden" name="roleId" id="roleId" value="${roleId}">
                <c:if test="${not empty firstMenuList}">
                    <c:forEach items="${firstMenuList}" var="temp">
                        <div>
                            <summary>${temp.firstName}</summary>
                        </div>
                        <div>
                            <c:if test="${not empty secondMenuList}">
                                &ensp;
                                <c:forEach items="${secondMenuList}" var="a">
                                    <c:if test="${temp.firstMenuId==a.firstMenuId}">
                                        <c:set var="flag" value="false"/>
                                        <c:forEach items="${secondMenu}" var="b">
                                            <c:if test="${b.secondMenuId==a.secondMenuId}">
                                                <c:set var="flag" value="true"/>
                                            </c:if>
                                        </c:forEach>
                                        <div class="checkbox checkbox-primary checkbox-inline">
                                            <input class='styled' type="checkbox" name="secondMenuId" id="secondMenuId"
                                                   value="${a.secondMenuId}" ${flag==true?'checked':''}>
                                                <%--<div class="checkbox checkbox-primary" style="float: left">--%>

                                                <%--<input id="checkbox2" class="styled" type="checkbox" checked>--%>
                                            <label class="permission-list">
                                                    ${a.secondMenuName}
                                            </label>
                                                <%--</div>--%>
                                                <%--<input   type="checkbox" name="secondMenuId" id="secondMenuId" value="${a.secondMenuId}" ${flag==true?'checked':''}>${a.secondMenuName}--%>
                                        </div>

                                    </c:if>
                                </c:forEach>
                            </c:if>
                        </div>
                    </c:forEach>
                </c:if>
            </div>
        </div>
        <input class="btn-sm btn-primary" type="button" value="确定" onclick="update()"/>
        <input class="btn-sm btn-primary" type="reset" value="取消"/>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="assets/H-ui/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="assets/H-ui/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="assets/H-ui/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="assets/H-ui/static/h-ui.admin/js/H-ui.admin.page.js"></script>

<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="assets/H-ui/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="assets/H-ui/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="assets/H-ui/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">


    function update() {

        var roleId = $("#roleId").val();
        var secondMenuId = new Array();

        $('input[name="secondMenuId"]:checked').each(function () {
            secondMenuId.push(
                $.trim($(this).val()
                )
            );
        });
        $.ajax({
            url: "power/up.action",
            data: {
                "roleId": roleId,
                "secondMenuId": secondMenuId
            },
            type: "post",
            success: function (result) {
                if (result = "true") {
                    layer.msg('分配成功', {icon: 1, time: 2000});
                } else {
                    layer.msg('分配失败', {icon: 1, time: 2000});
                }

            }

        });
    }


    // $(function(){
    //     $(".permission-list dt input:checkbox").click(function(){
    //         $(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    //     });
    //     $(".permission-list2 dd input:checkbox").click(function(){
    //         var l =$(this).parent().parent().find("input:checked").length;
    //         var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
    //         if($(this).prop("checked")){
    //             $(this).closest("dl").find("dt input:checkbox").prop("checked",true);
    //             $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
    //         }
    //         else{
    //             if(l==0){
    //                 $(this).closest("dl").find("dt input:checkbox").prop("checked",false);
    //             }
    //             if(l2==0){
    //                 $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
    //             }
    //         }
    //     });
    //
    //     $("#form-admin-role-add").validate({
    //         rules:{
    //             roleName:{
    //                 required:true,
    //             },
    //         },
    //         onkeyup:false,
    //         focusCleanup:true,
    //         success:"valid",
    //         submitHandler:function(form){
    //             $(form).ajaxSubmit();
    //             var index = parent.layer.getFrameIndex(window.name);
    //             parent.layer.close(index);
    //         }
    //     });
    // });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>